package com.charles.springmvc.web.ch4_5;

import java.io.File;
import java.io.IOException;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.apache.commons.io.FileUtils;
/**
 * Created by charles on 2017/5/11.
 */
@Controller
public class UploadController {

    @RequestMapping(value = "/upload",method = RequestMethod.POST)
    public @ResponseBody String upload(MultipartFile file) {
        try {
            FileUtils.writeByteArrayToFile(new File("file/upload/" + file.getOriginalFilename()),file.getBytes());
            return "OK";
        }catch (IOException e) {
            e.printStackTrace();
            return "Wrong";
        }
    }
}
